use rocket::serde::{Serialize,Deserialize};
use crate::RB;

crud!(GoodsShopcart{});
// impl_insert!(GoodsShopCart{add_to_shop_cart(goodId:u32,num:u32,userId:u32)=>"`(user_id, goods_id, num, status) VALUES (#{userId}, #{goodId), #{num}, 1)`"});
impl_select!(GoodsShopcart{selectByGoodIdAndUserId(goodId:u32,userId:u32)=>"`where user_id = #{userId} and goods_id = #{goodId} and status != 2`"});

#[derive(Serialize,Deserialize,Clone,Debug)]
pub struct GoodsShopcart {
    pub id:Option<u32>,
    pub user_id:Option<u32>,
    pub goods_id:Option<u32>,
    pub num:Option<u32>,
    pub status:Option<u32>,
}

impl GoodsShopcart{
    pub async fn update_by_user_id_set_status(user_id:u32)->Vec<GoodsShopcart>{
        let mut rb = RB.clone();
        let query = rb.query_decode("UPDATE goods_shopcart set status = 2 where user_id = ? and status = 1", vec![rbs::to_value!(user_id)]).await.unwrap();
        query
    }
}